<?php
/*
 * session.php
 *
 * Copyright (C) 2006 - OS3 srl - http://www.os3.it
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this software; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

/*
	This class is responsible of handling all session data.
	You can get and set session values that will be remembered among user
	browsing your site simply calling $sess->get() and $sess->set() functions.

	Internally, the array is actualy a global variable, called $_session_data.
	Please, do not use this variable directly, since it could change in the future.

	The session creation *must* be the first thing in your PHP program before any output
	to the user. Call the function session_new() to have back a valid (and initialized)
	session_manager instance.
*/
class session_manager 
{
	function session_manager ()
	{
		session_start ();
	}

	function set ( $name, $value )
	{
		$_SESSION [ strtolower ( $name ) ] = $value;
	}

	function del ( $name )
	{
		unset ( $_SESSION [ strtolower ( $name ) ] );
	}

	function get ( $name, $defval = false )
	{
		$name = strtolower ( $name );
		if ( isset ( $_SESSION [ $name ] ) ) return $_SESSION [ $name ];

		return $defval;
	}

	function check ( $name )
	{
		$name = strtolower ( $name );
		if ( isset ( $_SESSION [ $name ] ) ) return ( true );

		return ( false );	
	}	

	function debug_dump ()
	{
		print ( "<pre>" );
		print_r ( $_SESSION );
		print ( "</pre>" );
	}

	function id () { return ( session_id () ); }

	function quit ()
	{
		$_SESSION [ "uid" ] = false;
		session_unset ();
	}
}
?>
